function [targetOrder] = ST_RandomTargetOrder(nrTargets, targetsPerBin, p_bin)
%ST_RandomTargetOrder Summary of this function goes here
% Detailed explanation goes here

targetOrder(1:targetsPerBin, 1:nrTargets) = 0;
a = 1;
b = 1;
k = 1;
while (a <= targetsPerBin) && (b <= nrTargets) && (k <= nrTargets)
  while 1
    targetOrder(a, b) = ceil(rand() * nrTargets);
    been_done = 0;
    for c = 1:targetsPerBin
      for d = 1:b
        if (c == a) && (d == b)
          continue;
        end
        if (targetOrder(a, b) == targetOrder(c, d))
          been_done = 1;
          break;
        end
      end
      if been_done
        break;
      end
    end
    if ~been_done
      break;
    end
  end
  k = k + 1;
  if (a == targetsPerBin) || (rand() >= p_bin)
    a = 1;
    b = b + 1;
  else
    a = a + 1;
  end
end
end